package com.shanzhu.st.service.impl;

import com.shanzhu.st.entity.Order;
import com.shanzhu.st.mapper.OrderMapper;
import com.shanzhu.st.service.OrderService;
import com.shanzhu.st.utils.OrderTask;
import com.shanzhu.st.utils.OrderTaskHandler;
import com.shanzhu.st.vo.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;



    private static HashMap<Integer, ReentrantLock> lockMap = new HashMap<>();

    static {
        for (int i = 0; i < 100; i++) {
            lockMap.put(i, new ReentrantLock(true));
        }
    }
    @Override
    public int addOrder(Order order) {

        return orderMapper.insert(order);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateOrder(Order order) {

        return orderMapper.updateByPrimaryKeySelective(order) == 1;
    }

    @Override
    public List<Order> getMyOrder(Long userId) {
        List<Order> list = orderMapper.getMyOrder(userId);

        return list;
    }

}
